﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using orm.efcore.api.Entities;

namespace orm.efcore.api.Controllers
{
    /// <summary>
    /// 批量操作
    /// </summary>
    public class BatchController(CoreDbContext dbContext) : EfCoreBaseController(dbContext)
    {
        /// <summary>
        /// 价格 + 1
        /// </summary>
        [HttpPut]
        public async Task<IActionResult> Update()
        {
            return Ok(await DbContext.Order
                .Where(o => true)
                .ExecuteUpdateAsync(setters => setters
                    .SetProperty(o => o.TotalPrice, o => o.TotalPrice + 1)) > 0);
        }

        [HttpDelete]
        public async Task<IActionResult> Delete()
        {
            return Ok(await DbContext.Order
                .Where(o => o.IsDeleted == false)
                .ExecuteDeleteAsync() > 0);
        }
    }
}
